package cn.zebra.dev.feign.service.impl;

import cn.zebra.dev.common.restful.Result;
import cn.zebra.dev.feign.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * @author runnable@sina.cn
 */
@Service
@Slf4j
public class SmsServiceImpl implements SmsService {

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public Result sendContent(Map<String, Object> param) {
        ResponseEntity<Result> responseEntity = restTemplate.postForEntity("http://smsApplication/sys/api/sms/sendContent", param, Result.class);
        if (!responseEntity.getStatusCode().is2xxSuccessful()) {
            log.error("参数:{}", param);
            return Result.error("发送失败!");
        }
        return responseEntity.getBody();
    }
}
